package cn.xiongxf.web.controller;

import cn.xiongxf.service.IUserIntegralLogService;
import cn.xiongxf.domain.UserIntegralLog;
import cn.xiongxf.query.UserIntegralLogQuery;
import cn.xiongxf.result.JsonResult;
import cn.xiongxf.result.PageList;
import cn.xiongxf.vo.GrowthValVO;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/userIntegralLog")
public class UserIntegralLogController {

    @Autowired
    public IUserIntegralLogService userIntegralLogService;

    /**
    * 带条件分页查询数据
    */
    @RequestMapping(value = "/pagelist",method = RequestMethod.POST)
    public JsonResult page(@RequestBody UserIntegralLogQuery query){
        Page<UserIntegralLog> page = new Page<UserIntegralLog>(query.getPage(),query.getRows());
        page = userIntegralLogService.selectPage(page);
        return JsonResult.success(new PageList<UserIntegralLog>(page.getTotal(),page.getRecords()));
    }

    /**
    * 查询所有对象
    */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public JsonResult list(){
        return JsonResult.success(userIntegralLogService.selectList(null));
    }

    /**
   * 查询单个对象
   */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public JsonResult get(@PathVariable("id")Long id){
        return JsonResult.success(userIntegralLogService.selectById(id));
    }

    /**
    * 删除对象
    */
    @RequestMapping(value="/{id}",method=RequestMethod.DELETE)
    public JsonResult delete(@PathVariable("id") Long id){
            userIntegralLogService.deleteById(id);
        return JsonResult.success();
    }

    /**
     * 根据用户ID获取积分
     */
    @RequestMapping(value="/getIntegral/{userId}",method= RequestMethod.GET)
    public JsonResult getIntegral(@PathVariable("userId") Long userId){
        Integer integral = userIntegralLogService.getIntegral(userId);
        return JsonResult.success(integral);
    }

}
